 #-*- codeing = utf-8 -*-
#@Time : 2020/11/25 14:45
#@Author : 阳某
#@File : 12.异常.py
#@Software : PyCharm

import traceback

try:
    100/0
except :
    print(traceback.format_exc())

# 异常对象，代表电话号码有非法字符
class InvalidCharError(Exception):
    pass

# 异常对象，代表电话号码非中国号码
class NotChinaTelError(Exception):
    pass
def register():
    tel = input('请注册您的电话号码:')

    # 如果有非数字字符
    if not tel.isdigit():
        raise InvalidCharError

    # 如果不是以86开头，则不是中国号码
    if not tel.startswith('86'):
        raise NotChinaTelError

    return tel


    try:
        ret = register()
    except InvalidCharError:
        print('电话号码中有错误的字符')
    except NotChinaTelError:
        print('非中国手机号码')


def level_3():
    print ('进入 level_3')
    a = [0]
    b = a[1]
    print ('离开 level_3')

def level_2():
    print ('进入 level_2')
    level_3()
    print ('离开 level_2')

def level_1():
    print ('进入 level_1')
    level_2()
    print ('离开 level_1')


# level_1()
try:
    level_1()
except :
    print(f'未知异常:{traceback.format_exc()}')
print('程序正常退出')